import { createStore, applyMiddleware } from "redux";
import thunk from 'redux-thunk'
import reducers from './reducers/main.js'
import logger from 'redux-logger'
const createHistory = require("history").createBrowserHistory
import { composeWithDevTools } from 'redux-devtools-extension'
import { routerMiddleware } from 'react-router-redux'

const history = createHistory()
history.replace('/menu')
const historyMiddleware = routerMiddleware(history);

const store = createStore(reducers, composeWithDevTools(applyMiddleware(thunk, historyMiddleware, logger)));
if (module.hot) {
    module.hot.accept("./reducers/main", () => {
        const nextRootReducer = require("./reducers/main.js").default;
        store.replaceReducer(nextRootReducer);
    });
}

module.exports = {
    store,
    history
}